package homework2;

/**
 * 商品类，包含编号、名字、种类、价格、销量和库存等属性。
 */
public class Product implements Comparable<Product>{
    private int id;//编号
    private String name;//名字
    private String category;//种类
    private double price;//价格
    private int sales;//销量
    private int stock;//库存

    public Product() {
    }

    // 构造方法
    public Product(int id, String name, String category, double price, int sales, int stock) {
        this.id = id;
        this.name = name;
        this.category = category;
        this.price = price;
        this.sales = sales;
        this.stock = stock;
    }

    // getter和setter方法
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getSales() {
        return sales;
    }

    public void setSales(int sales) {
        this.sales = sales;
    }

    public int getStock() {
        return stock;
    }

    public void setStock(int stock) {
        this.stock = stock;
    }

    // toString方法，用于打印商品信息
    @Override
    public String toString() {
        return "Product{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", category='" + category + '\'' +
                ", price=" + price +
                ", sales=" + sales +
                ", stock=" + stock +
                '}';
    }

    @Override
    public int compareTo(Product o) {
        //正序排序4
        return this.sales-o.sales;
    }
}